//
//  ZLZKWKwebviewControllerViewController.m
//  ZLZKBaseUtils_Example
//
//  Created by sxh on 2021/4/8.
//  Copyright © 2021 1134548344@qq.com. All rights reserved.
//

#import "ZLZKWKwebviewControllerViewController.h"
#import <WebKit/WebKit.h>
#import "NSURLProtocol+WKWebView.h"

@interface ZLZKWKwebviewControllerViewController ()
<
    WKNavigationDelegate
>
@property (nonatomic , strong) NSURLRequest *request;
@end

@implementation ZLZKWKwebviewControllerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [NSURLProtocol wk_registerScheme:@"http"];
    [NSURLProtocol wk_registerScheme:@"https"];
    
    [self initView];
}

- (void)initView {
    NSString *urlStr = @"http://www.baidu.com";
    
    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
    
    WKWebView *web = [[WKWebView alloc] initWithFrame:self.view.frame configuration:configuration];
    
    [self.view addSubview:web];
    
//    NSString *urlStrEncoding = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLUserAllowedCharacterSet]];
    
    web.navigationDelegate = self;
    
    NSURL *url = [NSURL URLWithString:urlStr];
    
    NSURLRequest *request = [NSURLRequest requestWithURL: url];
    
    _request = request;
    
    [web loadRequest:request];
}


- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
    
    NSLog(@"%@",NSTemporaryDirectory());
}


@end
